// package com.dd.controller;

// import com.dd.model.AQIData;
// import com.dd.service.AQIDataService;
// import javafx.collections.FXCollections;
// import javafx.collections.ObservableList;
// import javafx.fxml.FXML;
// import javafx.fxml.FXMLLoader;
// import javafx.scene.Parent;
// import javafx.scene.Scene;
// import javafx.scene.control.Alert;
// import javafx.scene.control.TableColumn;
// import javafx.scene.control.TableView;
// import javafx.scene.control.TextField;
// import javafx.scene.control.cell.PropertyValueFactory;
// import javafx.stage.Modality;
// import javafx.stage.Stage;

// import java.io.IOException;
// import java.util.List;
// import java.util.stream.Collectors;

// public class ConfirmAqiDataListController {

//     @FXML
//     private TextField gridWorkerFilterField;
//     @FXML
//     private TextField provinceFilterField;
//     @FXML
//     private TextField cityFilterField;
//     @FXML
//     private TableView<AQIData> aqiDataTable;
//     @FXML
//     private TableColumn<AQIData, String> idCol;
//     @FXML
//     private TableColumn<AQIData, String> gridWorkerCol;
//     @FXML
//     private TableColumn<AQIData, String> submissionTimeCol;
//     @FXML
//     private TableColumn<AQIData, String> provinceCol;
//     @FXML
//     private TableColumn<AQIData, String> cityCol;
//     @FXML
//     private TableColumn<AQIData, String> addressCol;
//     @FXML
//     private TableColumn<AQIData, Double> so2Col;
//     @FXML
//     private TableColumn<AQIData, Double> coCol;
//     @FXML
//     private TableColumn<AQIData, Double> pm25Col;
//     @FXML
//     private TableColumn<AQIData, String> actualAqiLevelCol;

//     private ObservableList<AQIData> dataList = FXCollections.observableArrayList();
//     private AQIDataService aqiDataService = new AQIDataService();

//     @FXML
//     public void initialize() {
//         // 初始化 TableColumn 和 AQIData 属性的映射
//         idCol.setCellValueFactory(new PropertyValueFactory<>("id"));
//         gridWorkerCol.setCellValueFactory(new PropertyValueFactory<>("gridWorkerName"));
//         submissionTimeCol.setCellValueFactory(new PropertyValueFactory<>("submissionTime"));
//         provinceCol.setCellValueFactory(new PropertyValueFactory<>("province"));
//         cityCol.setCellValueFactory(new PropertyValueFactory<>("city"));
//         addressCol.setCellValueFactory(new PropertyValueFactory<>("specificAddress"));
//         so2Col.setCellValueFactory(new PropertyValueFactory<>("so2Concentration"));
//         coCol.setCellValueFactory(new PropertyValueFactory<>("coConcentration"));
//         pm25Col.setCellValueFactory(new PropertyValueFactory<>("pm25Concentration"));
//         actualAqiLevelCol.setCellValueFactory(new PropertyValueFactory<>("actualAqiLevel"));

//         loadAQIData();
//     }

//     private void loadAQIData() {
//         dataList.clear();
//         dataList.addAll(aqiDataService.getAllAQIData());
//         aqiDataTable.setItems(dataList);
//     }

//     @FXML
//     private void handleQueryClick() {
//         String gridWorker = gridWorkerFilterField.getText().trim();
//         String province = provinceFilterField.getText().trim();
//         String city = cityFilterField.getText().trim();

//         List<AQIData> filteredList = aqiDataService.getAllAQIData().stream()
//                 .filter(data -> (gridWorker.isEmpty() || data.getGridWorkerName().contains(gridWorker)) &&
//                         (province.isEmpty() || data.getProvince().contains(province)) &&
//                         (city.isEmpty() || data.getCity().contains(city)))
//                 .collect(Collectors.toList());
//         dataList.setAll(filteredList);
//     }

//     @FXML
//     private void handleResetClick() {
//         gridWorkerFilterField.clear();
//         provinceFilterField.clear();
//         cityFilterField.clear();
//         loadAQIData();
//     }

//     @FXML
//     private void handleViewDetailsClick() {
//         AQIData selectedData = aqiDataTable.getSelectionModel().getSelectedItem();
//         if (selectedData != null) {
//             try {
//                 FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/dd/aqi_data_details.fxml"));
//                 Parent parent = loader.load();

//                 AqiDataDetailsController controller = loader.getController();
//                 controller.initData(selectedData);

//                 Stage stage = new Stage();
//                 stage.setTitle("AQI数据详情");
//                 stage.setScene(new Scene(parent));
//                 stage.initModality(Modality.APPLICATION_MODAL);
//                 stage.showAndWait();

//             } catch (IOException e) {
//                 e.printStackTrace();
//                 showAlert(Alert.AlertType.ERROR, "错误", "无法加载详情界面。");
//             }
//         } else {
//             showAlert(Alert.AlertType.WARNING, "未选择", "请先从列表中选择一条数据。");
//         }
//     }

//     private void showAlert(Alert.AlertType alertType, String title, String message) {
//         Alert alert = new Alert(alertType);
//         alert.setTitle(title);
//         alert.setHeaderText(null);
//         alert.setContentText(message);
//         alert.showAndWait();
//     }
// }
